home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / Word.sig < prev    next >
Encoding:
Text File  |  1996-07-03  |  4.1 KB  |  118 lines  |  [TEXT/R*ch]

  1. (* Word -- SML Standard Library *)
  2.  
  3. eqtype word
  4. val wordSize : int
  5.  
  6. val wordToInt  : word -> int
  7. val signExtend : word -> int
  8. val intToWord  : int -> word
  9.  
  10. val orb  : word * word -> word
  11. val andb : word * word -> word
  12. val xorb : word * word -> word
  13. val notb : word -> word
  14.  
  15. val <<  : word * word -> word
  16. val >>  : word * word -> word
  17. val ~>> : word * word -> word
  18.  
  19. val +   : word * word -> word
  20. val -   : word * word -> word
  21. val *   : word * word -> word
  22. val div : word * word -> word
  23. val mod : word * word -> word
  24.  
  25. val >   : word * word -> bool
  26. val <   : word * word -> bool
  27. val >=  : word * word -> bool
  28. val <=  : word * word -> bool
  29. val compare : word * word -> ordering
  30.  
  31. val toString   : word -> string
  32. val fromString : string -> word option
  33. val scan : StringCvt.radix -> {getc : 'a -> (char * 'a) option} 
  34.            -> 'a -> (word * 'a) option
  35. val fmt  : StringCvt.radix -> word -> string
  36.  
  37. (* [word] is the type of n-bit words, or n-bit unsigned integers.
  38.  
  39.    [wordSize] is the value of n above.  In Moscow ML, n=31 on 32-bit
  40.    machines and n=63 on 64-bit machines.
  41.  
  42.    [wordToInt w] returns the (signed) integer represented by bit-pattern w.
  43.  
  44.    [signExtend w] returns the (signed) integer represented by bit-pattern w.
  45.  
  46.    [intToWord i] returns the word representing i.
  47.  
  48.    [orb(w1, w2)] returns the bitwise `or' of w1 and w2.
  49.  
  50.    [andb(w1, w2)] returns the bitwise `and' of w1 and w2.
  51.  
  52.    [xorb(w1, w2)] returns the bitwise `exclusive or' or w1 and w2.
  53.  
  54.    [notb w] returns the bitwise negation of w.
  55.  
  56.    [<<(w, k)] returns the word resulting from shifting w left by k
  57.    bits.  The bits shifted in are zero, so this is a logical shift.
  58.    Consequently, the result is 0-bits when k >= wordSize.
  59.  
  60.    [>>(w, k)] returns the word resulting from shifting w right by k
  61.    bits.  The bits shifted in are zero, so this is a logical shift.
  62.    Consequently, the result is 0-bits when k >= wordSize.
  63.  
  64.    [~>>(w, k)] returns the word resulting from shifting w right by k
  65.    bits.  The bits shifted in are replications of the left-most bit:
  66.    the `sign bit', so this is an arithmetical shift.  Consequently,
  67.    for k >= wordSize and wordToInt w >= 0 the result is all 0-bits, and 
  68.    for k >= wordSize and wordToInt w <  0 the result is all 1-bits.
  69.  
  70.    To make <<, >>, and ~>> infix, use the declaration 
  71.               infix 5 << >> ~>>
  72.  
  73.    [+, -, *, div, mod] represent unsigned integer addition,
  74.    subtraction, multiplication, division, and remainder, modulus two
  75.    to wordSize.  The operations (i div j) and (i mod j) raise Div when
  76.    j=0.  Otherwise no exceptions are raised.
  77.  
  78.    [w1 > w2] returns true if the unsigned integer represented by w1
  79.    is larger than that of w2, and similarly for <, >=, <=.  
  80.  
  81.    [compare(w1, w2)] returns LESS, EQUAL, or GREATER, according 
  82.    as w1 is less than, equal to, or greater than w2 (as unsigned integers).
  83.  
  84.    [fmt radix w] returns a string representing w, in the radix (base)
  85.    specified by radix.
  86.  
  87.      radix    description                    
  88.      ---------------------------------------
  89.       BIN     unsigned binary      (base  2) 
  90.       OCT     unsigned octal       (base  8)   
  91.       DEC     unsigned decimal     (base 10)   
  92.       HEX     unsigned hexadecimal (base 16)   
  93.  
  94.    [toString w] returns a string representing w in unsigned
  95.    hexadecimal format.  Equivalent to (fmt HEX w).
  96.    
  97.    [fromString s] returns SOME(w) if a hexadecimal unsigned numeral
  98.    can be scanned from a prefix of string s, ignoring any initial
  99.    whitespace; returns NONE otherwise.  An unsigned hexadecimal
  100.    numeral must have form, after possible initial whitespace:
  101.        [0-9a-fA-F]+
  102.  
  103.    [scan radix {getc} charsrc] attempts to scan an unsigned numeral
  104.    from the character source charsrc, using the accessor getc, and
  105.    ignoring any initial whitespace.  The radix argument specifies the
  106.    base of the numeral (BIN, OCT, DEC, HEX).  If successful, it
  107.    returns SOME(w, rest) where w is the value of the numeral scanned,
  108.    and rest is the unused part of the character source.  A numeral
  109.    must have form, after possible initial whitespace:
  110.  
  111.      radix    format 
  112.      ---------------------
  113.       BIN     [0-1]+
  114.       OCT     [0-7]+
  115.       DEC     [0-9]+
  116.       HEX     [0-9a-fA-F]+
  117. *)
  118.